//
//  ZyaPurchaseDetailCell.swift
//  SlaughterClient
//
//  Created by Zhouweibin on 2018/1/29.
//  Copyright © 2018年 zwb. All rights reserved.
//

import UIKit

//s_goods_type:商品类别
//s_goods_code:商品代码
//s_goods_nm:商品名称
//s_goods_spec:规格
//s_goods_bz:标包
//s_amount_t:确认数量
//s_cess_price:单价
//s_money_t:确认金额
//s_exe_amount:已入库数量

class ZyaPurchaseDetailCell: UITableViewCell {
    
    var isShow = false

    @IBOutlet weak var name: UILabel!
    @IBOutlet weak var code: UILabel!
    @IBOutlet weak var type: UILabel!
    @IBOutlet weak var spec: UILabel!
    @IBOutlet weak var bz: UILabel!
    @IBOutlet weak var amount: UILabel!
    @IBOutlet weak var exeAmount: UILabel!
    @IBOutlet weak var price: UILabel!
    @IBOutlet weak var money: UILabel!
    @IBOutlet weak var header: UIView!
    
    var deleteClosure:(()->())?
    
    var model: ZyaPurchaseDetail? {
        didSet {
            
            guard let item = model else {
                return
            }
            
            name.text = item.sGoodsNm
            code.text = item.sGoodsCode
            type.text = item.sGoodsType
            spec.text = "规格:" +  (item.sGoodsSpec ?? "")
            bz.text = "标包:" + (item.sGoodsBz ?? "")
            amount.text = "确认数量:" + (item.sAmountT ?? "")
            exeAmount.text = "已入库数量:" + (item.sExeAmount ?? "")
            price.text = "单价:" + (item.sCessPrice ?? "")
            money.text = "确认金额:" + (item.sMoneyT ?? "")
            
            if !isShow {
                price.text = ""
                money.text = ""
            }
        }
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        // Configure the view for the selected state
    }
    
//    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
//        super.init(style: style, reuseIdentifier: reuseIdentifier)
//
    
        
//        addSubview(bgView)
//
//        bgView.addSubview(goodsNmLabel)
//        bgView.addSubview(goodsCodeLabel)
//        bgView.addSubview(goodsTypeLabel)
//        bgView.addSubview(goodsSpecLabel)
//        bgView.addSubview(goodsBzLabel)
//        bgView.addSubview(amountLabel)
//        bgView.addSubview(cessPriceLabel)
//        bgView.addSubview(moneyLabel)
//        bgView.addSubview(exeAmountLabel)
  
//        setupConstraints()
//    }
    @IBAction func deleAction(_ sender: Any) {
        if let clo = deleteClosure {
            clo()
        }
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        
        header.backgroundColor = UIColor(kshex: "#378C67")
        backgroundColor = Theme.backgroudColor
        selectionStyle = .none
    }
    
    private func setupConstraints () {
        
        bgView.snp.makeConstraints { (maker) in
            maker.edges.equalTo(UIEdgeInsets(top: 4, left: 8, bottom: 4, right: 8))
        }

        goodsNmLabel.snp.makeConstraints { (maker) in
            maker.left.equalTo(8)
            maker.top.equalTo(12)
        }
        
        goodsCodeLabel.snp.makeConstraints { (maker) in
            maker.left.equalTo(8)
            maker.right.equalTo(goodsTypeLabel.snp.left).offset(-4)
            maker.top.equalTo(goodsNmLabel.snp.bottom).offset(12)
        }
        
        goodsTypeLabel.snp.makeConstraints { (maker) in
            maker.left.equalTo(bgView.snp.right).offset(-150)
            maker.centerY.equalTo(goodsCodeLabel)
        }
        
        goodsSpecLabel.snp.makeConstraints { (maker) in
            maker.left.equalTo(8)
            maker.right.equalTo(goodsBzLabel.snp.left).offset(-4)
            maker.top.equalTo(goodsCodeLabel.snp.bottom).offset(12)
        }
        
        goodsBzLabel.snp.makeConstraints { (maker) in
            maker.left.equalTo(bgView.snp.right).offset(-150)
            maker.centerY.equalTo(goodsSpecLabel)
        }
        
        amountLabel.snp.makeConstraints { (maker) in
            maker.left.equalTo(8)
            maker.top.equalTo(goodsSpecLabel.snp.bottom).offset(12)
        }
        
        exeAmountLabel.snp.makeConstraints { (maker) in
            maker.left.equalTo(bgView.snp.right).offset(-150)
            maker.centerY.equalTo(amountLabel)
        }
        
        cessPriceLabel.snp.makeConstraints { (maker) in
            maker.left.equalTo(8)
            maker.top.equalTo(amountLabel.snp.bottom).offset(12)
            maker.bottom.equalTo(-12)
        }
        
        moneyLabel.snp.makeConstraints { (maker) in
            maker.left.equalTo(bgView.snp.right).offset(-150)
            maker.centerY.equalTo(cessPriceLabel)
        }
        
    }
    
    lazy var bgView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor.white
        return view
    } ()
    
    lazy var goodsNmLabel: UILabel = {
        let label = UILabel()
        label.textColor = Theme.textColor
        label.font = UIFont.boldSystemFont(ofSize: 15)
        return label
    } ()
    
    lazy var moneyLabel: UILabel = {
        let label = UILabel()
        label.textColor = Theme.textColor
        label.font = UIFont.systemFont(ofSize: 14)
        return label
    } ()
    
    lazy var goodsSpecLabel: UILabel = {
        let label = UILabel()
        label.textColor = Theme.textColor
        label.font = UIFont.systemFont(ofSize: 14)
        return label
    } ()
    
    lazy var goodsTypeLabel: UILabel = {
        let label = UILabel()
        label.textColor = Theme.textColor
        label.font = UIFont.systemFont(ofSize: 14)
        return label
    } ()
    
    lazy var goodsCodeLabel: UILabel = {
        let label = UILabel()
        label.textColor = Theme.textColor
        label.numberOfLines = 0
        label.font = UIFont.systemFont(ofSize: 14)
        return label
    } ()
    
    lazy var goodsBzLabel: UILabel = {
        let label = UILabel()
        label.textColor = Theme.textColor
        label.font = UIFont.systemFont(ofSize: 14)
        return label
    } ()
    
    lazy var amountLabel: UILabel = {
        let label = UILabel()
        label.textColor = Theme.textColor
        label.font = UIFont.systemFont(ofSize: 14)
        return label
    } ()
    
    lazy var cessPriceLabel: UILabel = {
        let label = UILabel()
        label.textColor = Theme.textColor
        label.font = UIFont.systemFont(ofSize: 14)
        return label
    } ()
    
    lazy var exeAmountLabel: UILabel = {
        let label = UILabel()
        label.textColor = Theme.textColor
        label.font = UIFont.systemFont(ofSize: 14)
        return label
    } ()
}
